﻿using System.Collections.Generic;
using System.Data;
using org.se.fs.presenter.Library;

namespace org.se.fs.presenter.View.Template
{
    public abstract class ViewLists<T> where T : class, new()
    {
        public event FormEvent.FormEventHandler OnSearch;
        public event FormEvent.FormEventHandler OnToggle;
        public event FormEvent.FormEventHandler OnDelete;
        public event FormEvent.FormEventHandler OnError;
        protected IList<T> Lists { get; set; }
        protected DataTable DataLists { get; set; }

        public void TriggerSearch(FormEvent e)
        {
            if (OnSearch != null)
                OnSearch(this, e);
        }

        public void TriggerToggle(FormEvent e)
        {
            if (OnToggle != null)
                OnToggle(this, e);
        }

        public void TriggerDelete(FormEvent e)
        {
            if (OnDelete != null)
                OnDelete(this, e);
        }

        public void TriggerError(FormEvent e)
        {
            if (OnError != null)
                OnError(this, e);
        }

        public T GetData(int index)
        {
            return Lists[index];
        }

        public virtual void DisplayData() {}

        public virtual void Add(T data)
        {
            if (data == null)
                return;
            Lists.Add(data);
            DisplayData();
        }
    }
}